package cn.edu.xmu.orderpayment.order.microservice.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Jiawei Zheng
 * @date 2021-11-26
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OnsaleVo {

    @ApiModelProperty(value = "OnsaleId")
    private Long id;

    @ApiModelProperty(value = "店铺")
    private ShopVo shop;

    @ApiModelProperty(value = "货品")
    private ProductVo product;

    @ApiModelProperty(value = "价格")
    private Long price;

    @ApiModelProperty(value = "开始时间")
    @DateTimeFormat(pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSXXX")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSXXX")    private ZonedDateTime beginTime;

    @ApiModelProperty(value = "结束时间")
    @DateTimeFormat(pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSXXX")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSXXX")    private ZonedDateTime endTime;

    @ApiModelProperty(value = "数量")
    private Long quantity;

    @ApiModelProperty(value = "类型")
    private Byte type;

    @ApiModelProperty(value = "活动id")
    private Long activityId;

    @ApiModelProperty(value = "分享活动id")
    private Long shareActId;

    @ApiModelProperty(value = "创建时间")
    @DateTimeFormat(pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSXXX")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSXXX")
    private ZonedDateTime gmtCreate;

    @ApiModelProperty(value = "修改时间")
    @DateTimeFormat(pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSXXX")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSXXX")
    private ZonedDateTime gmtModified;

    public enum State {
        DRAFT((byte) 0, "草稿"),
        ONLINE((byte) 1, "上线"),
        OFFLINE((byte) 2, "下线");


        private static final Map<Byte, State> STATE_MAP;

        static { //由类加载机制，静态块初始加载对应的枚举属性到map中，而不用每次取属性时，遍历一次所有枚举值
            STATE_MAP = new HashMap();
            for (State enum1 : values()) {
                STATE_MAP.put(enum1.code, enum1);
            }
        }

        private Byte code;
        private String description;

        State(Byte code, String description) {
            this.code=code;
            this.description=description;
        }

        public static State getStatusByCode(Byte code){
            return STATE_MAP.get(code);
        }

        public Byte getCode(){
            return code;
        }

        public String getDescription() {return description;}

    }

    @Data
    class ShareAct {
        private Long id;
        private String name;
    }

    @Data
    class CreatedBy {
        private Long id;
        private String username;
    }

    @Data
    class ModifiedBy {
        private Long id;
        private String username;
    }

    private ShareAct shareAct;

    private CreatedBy createdBy;

    private ModifiedBy modifiedBy;
}
